package cn.stylefeng.guns.modular.business.service.Impl;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.modular.business.entity.CanalThreeClassify;
import cn.stylefeng.guns.modular.business.mapper.CanalThreeClassifyMapper;
import cn.stylefeng.guns.modular.business.service.CanalThreeClassifyService;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class CanalThreeClassifyServiceImpl extends ServiceImpl<CanalThreeClassifyMapper, CanalThreeClassify> implements CanalThreeClassifyService {



    @Override
    public CanalThreeClassify detail(CanalThreeClassify canalThreeClassify) {
        return this.queryCar(canalThreeClassify);
    }

    @Override
    public PageResult<CanalThreeClassify> findPage(CanalThreeClassify canalThreeClassify) {
        LambdaQueryWrapper<CanalThreeClassify> wrapper = createWrapper(canalThreeClassify);
        Page<CanalThreeClassify> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
        return PageResultFactory.createPageResult(sysRolePage);
    }

    @Override
    public  List<CanalThreeClassify>  findThreeList(CanalThreeClassify canalThreeClassify) {
        LambdaQueryWrapper<CanalThreeClassify> queryWrapper = new LambdaQueryWrapper<>();
        List<Map<String,Object>> mapList = new ArrayList<>();
        String name = canalThreeClassify.getCanalSecondClassifyCode();
        queryWrapper.eq(ObjectUtil.isNotEmpty(name), CanalThreeClassify::getCanalSecondClassifyCode, name);
//        List<CanalThreeClassify> canalThreeClassifyList = this.list(queryWrapper);
//        for(CanalThreeClassify threeClassify : canalThreeClassifyList){
//
//            Map<String, Object> map = new HashMap<String, Object>();
//            Map<String, Object> map1 = new HashMap<String, Object>();
//
//            map.put("canalThreeClassifyName",threeClassify.getCanalThreeClassifyName());
//            map.put("canalThreeClassifyCode",threeClassify.getCanalThreeClassifyCode());
//            map.put("canalSecondClassifyCode",threeClassify.getCanalSecondClassifyCode());
//            map.put("canalFirstClassifyCode",threeClassify.getCanalFirstClassifyCode());
//            mapList.add(map);
//
//        }
         return this.list(queryWrapper);
    }

    /**
     * 获取信息
     */
    private CanalThreeClassify queryCar(CanalThreeClassify canalThreeClassify) {
        CanalThreeClassify secondClassfiy =this.getById(canalThreeClassify.getId());
        if (ObjectUtil.isEmpty(secondClassfiy)) {
            return null;
        }
        return secondClassfiy;
    }

    /**
     * 创建查询wrapper
     */
    private LambdaQueryWrapper<CanalThreeClassify> createWrapper(CanalThreeClassify canalThreeClassify) {
        LambdaQueryWrapper<CanalThreeClassify> queryWrapper = new LambdaQueryWrapper<>();

        String name = canalThreeClassify.getCanalFirstClassifyCode();
        queryWrapper.like(ObjectUtil.isNotEmpty(name), CanalThreeClassify::getCanalFirstClassifyCode, name);

        return queryWrapper;
    }
}
